import java.util.Stack;

class MinStack {
     protected Stack<Integer> stack1;
     protected Stack<Integer> minStack;
    public MinStack() {
        stack1=new Stack<>();
        minStack=new Stack<>();
    }
    public void push(int val) {
        stack1.push(val);
        if(minStack.empty()){
            minStack.push(val);
        }else{
            int x=minStack.peek();
            if(val<=x){
                minStack.push(val);
            }
        }
    }
    
    public void pop() {
        int x=stack1.pop();
        if(x==minStack.peek()){
            minStack.pop();
        }
    }
    
    public int top() {
        if(stack1.empty()){
            return -1;
        }
        return stack1.peek();

    }
    
    public int getMin() {
        if(minStack.empty()){
            return -1;
        }
      return minStack.peek();
    }
}